home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_6_6.arc / 66L2.ASM < prev    next >
Assembly Source File  |  1988-08-17  |  3KB  |  121 lines

  1. ;
  2. ; *** Listing 2 ***
  3. ;
  4. ; Program to restore a mode 10h EGA graphics screen from
  5. ; the file SNAPSHOT.SCR.
  6. ;
  7. VGA_SEGMENT    equ    0a000h
  8. SC_INDEX    equ    3c4h    ;Sequence Controller Index register
  9. MAP_MASK    equ    2    ;Map Mask register index in SC
  10. DISPLAYED_SCREEN_SIZE equ (640/8)*350
  11.                 ;# of displayed bytes per plane in a
  12.                 ; hi-res graphics screen
  13. ;
  14. stack    segment para stack 'STACK'
  15.     db    512 dup (?)
  16. stack    ends
  17. ;
  18. Data    segment    word 'DATA'
  19. Filename db    'SNAPSHOT.SCR',0 ;name of file we're restoring from
  20. ErrMsg1    db    '*** Couldn''t open SNAPSHOT.SCR ***',0dh,0ah,'$'
  21. ErrMsg2    db    '*** Error reading from SNAPSHOT.SCR ***',0dh,0ah,'$'
  22. WaitKeyMsg db    0dh, 0ah, 'Done. Press any key to end...',0dh,0ah,'$'
  23. Handle    dw    ?    ;handle of file we're restoring from
  24. Plane    db    ?    ;plane being written
  25. Data    ends
  26. ;
  27. Code    segment
  28.     assume    cs:Code, ds:Data
  29. Start    proc    near
  30.     mov    ax,Data
  31.     mov    ds,ax
  32. ;
  33. ; Go to hi-res graphics mode.
  34. ;
  35.     mov    ax,10h    ;AH = 0 means mode set, AL = 10h selects
  36.             ; hi-res graphics mode
  37.     int    10h    ;BIOS video interrupt
  38. ;
  39. ; Open SNAPSHOT.SCR.
  40. ;
  41.     mov    ah,3dh    ;DOS open file function
  42.     mov    dx,offset Filename
  43.     sub    al,al        ;open for reading
  44.     int    21h
  45.     mov    [Handle],ax    ;save the handle
  46.     jnc    RestoreTheScreen ;we're ready to restore if no error
  47.     mov    ah,9        ;DOS print string function
  48.     mov    dx,offset ErrMsg1
  49.     int    21h        ;notify of the error
  50.     jmp    short Done    ;and done
  51. ;
  52. ; Loop through the 4 planes, making each writable in turn and
  53. ; reading it from disk. Note that all 4 planes are writable at
  54. ; A000:0000; the Map Mask register selects which planes are readable
  55. ; at any one time. We only make one plane readable at a time.
  56. ;
  57. RestoreTheScreen:
  58.     mov    [Plane],0    ;start with plane 0
  59. RestoreLoop:
  60.     mov    dx,SC_INDEX
  61.     mov    al,MAP_MASK    ;set SC Index to Map Mask register
  62.     out    dx,al
  63.     inc    dx
  64.     mov    cl,[Plane]    ;get the # of the plane we want
  65.                 ; to restore
  66.     mov    al,1
  67.     shl    al,cl    ;set the bit enabling writes to
  68.             ; only the one desired plane
  69.     out    dx,al    ;set to read from the desired plane
  70.     mov    ah,3fh    ;DOS read from file function
  71.     mov    bx,[Handle]
  72.     mov    cx,DISPLAYED_SCREEN_SIZE ;# of bytes to read
  73.     sub    dx,dx    ;start loading bytes at A000:0000
  74.     push    ds
  75.     mov    si,VGA_SEGMENT
  76.     mov    ds,si
  77.     int    21h    ;read the displayed portion of this plane
  78.     pop    ds
  79.     jc    ReadError
  80.     cmp    ax,DISPLAYED_SCREEN_SIZE ;did all bytes get read?
  81.     jz    RestoreLoopBottom
  82. ReadError:
  83.     mov    ah,9        ;DOS print string function
  84.     mov    dx,offset ErrMsg2
  85.     int    21h        ;notify about the error
  86.     jmp    short DoClose    ;and done
  87. RestoreLoopBottom:
  88.     mov    al,[Plane]
  89.     inc    ax    ;point to the next plane
  90.     mov    [Plane],al
  91.     cmp    al,3    ;have we done all planes?
  92.     jbe    RestoreLoop ;no, so do the next plane
  93. ;
  94. ; Close SNAPSHOT.SCR.
  95. ;
  96. DoClose:
  97.     mov    ah,3eh    ;DOS close file function
  98.     mov    bx,[Handle]
  99.     int    21h
  100. ;
  101. ; Wait for a keypress.
  102. ;
  103.     mov    ah,8    ;DOS input without echo function
  104.     int    21h
  105. ;
  106. ; Restore text mode.
  107. ;
  108.     mov    ax,3
  109.     int    10h
  110. ;
  111. ; Done.
  112. ;
  113. Done:
  114.     mov    ah,4ch    ;DOS terminate function
  115.     int    21h
  116. Start    endp
  117. Code    ends
  118.     end    Start
  119.  
  120.  
  121.